<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>办公系统</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
{[include file="jquery-ui-1.10.3.tpl"]}
<link type="text/css" href="inc/style.all.css?r={[$smarty.now]}" rel="stylesheet">

<link href="inc/bootstrap.min.css?r={[$smarty.now]}" rel="stylesheet">
<link href="inc/bootstrap-responsive.css?r={[$smarty.now]}" rel="stylesheet">
<link href="inc/my_red.css?r={[$smarty.now]}" rel="stylesheet">

{[include file="_plugin.tpl"]}

{[include file="_js.tpl"]}
</head>

<body>
{[$msg]}
<div class="container-fluid" style="margin-top: 20px;">
	<div class='span4'></div>
	<div class='span4'>
		<div class="widget widget-table " style="margin: auto;">

			<div class="widget-header">
				<i class="icon-home"></i>
				<h3>登陆</h3>
			</div>
			<!-- /widget-header -->

			<div class="widget-content">
				<div class="box-content" style="text-align: center;">
					<div class="page-header">
						<h2>办公系统</h2>
					</div>
					<div id='client-msg'></div>
					<form id="form_login" class="form">

						<div class="control-group">
							<div class="controls">
								<div class="input-prepend input-append">
									<span class="add-on"><i class="icon-user"></i></span>
									<input class="input-width80" type="text"
										name="username" id="username" autocomplete="off" title="用户名">
								</div>
							</div>
						</div>
						<div class="control-group">
							<div class="controls">
								<div class="input-prepend input-append">
									<span class="add-on"><i class="icon-lock"></i></span><input
										class="input-width80" type="password"
										name="password" id="password" title="密码">
								</div>
							</div>
						</div>
						<div style='margin: auto; width: 250px'>
							<label class="checkbox" title='请不要在公共电脑上记住你的用户名密码！'
								style='width: 120px;'> <input type="checkbox"
								id='remind_password' name='remind_password'> 记住用户名和密码
							</label>
						</div>
						<div class="form-actions">
							<button type="button" class="btn btn-primary pull-right"
								id='btn_login' onclick="login();">登 陆</button>
						</div>
					</form>
					<hr>
					<footer>
						<p>&copy; {[$smarty.now|date_format:'%Y']} 一点通网络</p>
					</footer>
				</div>
			</div>
		</div>
	</div>
	<div class='span4'></div>
</div>

{[include file="_plugin.tpl"]}

{[include file="_js.tpl"]}

<script type="text/javascript">

$(function() {
	
	var username = $.cookie('username');
	var password = $.cookie('password');
	var remind_password = $.cookie('remind_password');
	
	if (remind_password == 'checked') {
		$("#remind_password").attr("checked", true);
	}
	
	$("#username").val(username);
	$("#password").val(password);
	
	$("input[id^='username']:visible").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: 'emp.php?do=Emp.ajax_zjm',
				dataType: "json",
				data: {
					featureClass: "P",
					style: "full",
					maxRows: 30,
					q: request.term
				},
				success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							label: item.name + " [" + item.zjm + ", " + item.dept_t + "]",
							value: item.name
						}
					}));
				}
			});
		},
		
		minLength: 1
	});
	
});

function login() {
	var body = $('#form_login').formSerialize();
	// alert(body);
	
	$.getJSON('?do=Admin.ajax_exist', body, function(json) {
		// alert($.toJSON(json));
		
		if (json.code == 0) {
			alert("用户名不存在，请重新输入！");
			return false;
		}
		
		if (json.data.status == 3) {
			alert("用户名已禁用，请联系管理员！");
			return false;
		}
		
		if (json.data.password == false) {
			alert("用户密码不对，请重新输入！");
			return false;
		}
		
		remind();
		
		window.open('?do=Admin.loginPost&'+body, '_self');
		// alert("OK");
	});	
}

function remind() {
	
	if ($("#remind_password").attr("checked")) {
		var username = $("#username").val();
		// alert(username);
		
		var password = $("#password").val();
		// alert(password);
		
		$.cookie('username', username, { expires: 7 }); 
		$.cookie('password', password, { expires: 7 });
		
		$.cookie('remind_password', 'checked', { expires: 7 });
	} else {
		$.cookie('username', '', { expires: -1 });
		$.cookie('password', '', { expires: -1 });
		$.cookie('remind_password', '', { expires: -1 });
	}
	
}
</script>

</body>
</html>